package com.example.jizhang.demos.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.jizhang.demos.dto.AccountInfoDTO;
import com.example.jizhang.demos.mapper.AccountInfoMapper;
import com.example.jizhang.demos.mapper.AccountMapper;
import com.example.jizhang.demos.pojo.AccountInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/** 账单详细表 服务层
 * @author 86195
 */
@Service
public class AccountInfoService extends ServiceImpl<AccountInfoMapper, AccountInfo> {


    @Autowired
    private AccountMapper accountMapper;

    @Autowired
    private AccountInfoMapper accountInfoMapper;

    /**
     * 加账 事务ok
     * @param dto
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public int add(AccountInfoDTO dto){
        dto.setInfoTime(new Date());
        //加账
        accountInfoMapper.add(dto);
        //加总账
        accountMapper.update(dto);
        return 1;
    }
}
